<?php
namespace Admin\Controller;
use Think\Controller;

class SysUserController extends Controller {
	public function index()
	{
		$this->moduleid 	= 'moduleid';
		$this->modulename = 'modulename';
		$this->url 		= 'url';
		$this->params 	= 'params';
		$this->target 	= 'target';
		$this->icon 		= 'icon';
		$this->sort 		= 'sort';
		$this->display();
	}

    public function getModule()
    {
        $data = $this->getChilds(-1);
        $this->ajaxReturn($data, 'json');
    }

    protected function getChilds($pid)
    {
        $data = array();
        $module = M('SysModule');
        $childs = $module->where('parentid='.$pid)->order('sort')->select();

        if(count($childs)>0){
            foreach ($childs as $child) {
                $data_child = array(
                    'id'        => $child[moduleid], 
                    'text'      => $child[modulename], 
                    'iconCls'   => $child[icon]
                );
                if($child[moduletype]==0){
                    $data_child[children] = $this->getChilds($child[moduleid]);
                };
                array_push($data, $data_child);
            }
        }

        return $data;
    }

    public function getCurrentModule($mid)
    {
        $module = M('SysModule');
        $data = $module->where('parentid='.$mid)->order('sort')->select();
        if(count($data)==0){
        	$data = $module->where('moduleid='.$mid)->select();
        }
        $this->ajaxReturn($data, 'json');
    }
}